package com.gis_luq.lib.Draw;

import java.io.FileNotFoundException;
import java.util.Enumeration;
import java.util.Vector;

/**
 * 监听类的父类 DrawTool继承了这个类，具备了添加监听的能力
 * 
 * @Author admin
 * @Date 2017-7-11 上午10:29:34
 */
public class Subject
{
	private Vector<DrawEventListener> repository = new Vector<DrawEventListener>();

	// 添加监听
	public void addEventListener(DrawEventListener listener)
	{
		this.repository.addElement(listener);
	}

	// 移除监听
	public void removeEventListener(DrawEventListener listener)
	{
		this.repository.removeElement(listener);
	}

	// 向监听者派发消息
	public void notifyEvent(DrawEvent event)
	{
		Enumeration<DrawEventListener> en = this.repository.elements();
		while (en.hasMoreElements())
		{
			DrawEventListener listener = en.nextElement();
			try
			{
				listener.handleDrawEvent(event);
			}
			catch (FileNotFoundException e)
			{
				e.printStackTrace();
			}
		}
	}
}
